home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12590 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  75 lines

  1. Newsgroups: comp.lang.c++,comp.os.ms-windows.programmer.misc
  2. Path: cs.mun.ca!michael9
  3. From: michael9@cs.mun.ca (Michael Sullivan)
  4. Subject: Help with FindNextPrinterChange
  5. Message-ID: <1996Mar19.232159.25236@cs.mun.ca>
  6. Keywords: C, MS Windows
  7. Sender: usenet@cs.mun.ca (NNTP server account)
  8. Organization: CS Dept., Memorial University of Newfoundland
  9. X-Newsreader: NN version 6.4.19
  10. Distribution: na
  11. Date: Tue, 19 Mar 1996 23:21:59 GMT
  12.  
  13.  
  14.  Hi there.  I'm new to programming for MS Windows, and have run into the 
  15. following problem:  in the code below, the call to FindFirstPrinterChange
  16. returns a 0x000000 value.  Which seems to be useless as a handle, but isn't
  17. equal to the INVALID_CHANGE_HANDLE that it should return when the call fails.
  18. Can someone tell me what I'm doing wrong?  How about sending me a sample
  19. file that uses FindFirstPrinterChange?   I'm currently using MS Visual C++ 4.0.
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <afx.h>
  24. #include <winspool.h>
  25. void main()
  26. {
  27.     HANDLE changeHandle;
  28.     HANDLE printer;
  29.  
  30.  
  31.     int i =0;
  32.  
  33.     if ( ! OpenPrinter("LPT1:", &printer, NULL) )
  34.     {
  35.         fprintf(stderr,  "Error opening printer.\n");
  36.     }
  37.  
  38.     changeHandle = FindFirstPrinterChangeNotification(printer, 
  39.         PRINTER_CHANGE_ADD_JOB,  (DWORD) 0,  NULL);
  40.  
  41. /* at this point, changeHandle is 0x0, which is not INV_HNDL. */
  42.  
  43.     if (changeHandle == 0 )  printf("Change failed\n");
  44.  
  45.     if ( changeHandle == INVALID_HANDLE_VALUE )
  46.     {
  47.         fprintf(stderr, "Can't open change handle.\n");
  48.     }
  49.  
  50.     while ( i++ < 3)
  51.     {
  52.         if ( (w = WaitForSingleObject(changeHandle, INFINITE)) == WAIT_FAILED);
  53.         {
  54.             // of course, this always fails
  55.             printf("wait failed\n");
  56.         }
  57.  
  58.         printf("Got ya!\n");
  59.     }
  60.  
  61.  
  62. }
  63.  
  64.  
  65.   I've tried various typecasts, and tried creating an LPHANDLE and assigning
  66. it the address of changeHandle before calling OpenPrinter, but that 
  67. didn't work either.  Advice?
  68.  
  69.  
  70. -- 
  71. |michael9@cs.mun.ca      |'"Proof denies faith and without faith I am nothing,"|
  72. |13 Liverpool,St.John's,NF| says God. "But you have given us proof," says man, |
  73. |A1C 3B1 (H)739-4185 (W)579-2730|  "Therefore you do not exist. QED." "Oh, my,"|
  74. |http://web.cs.mun.ca/~michael9 | says God, and disappears in a puff of logic.'|
  75.